package com.heima.article.controller.v1;

import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.article.dtos.ArticleInfoDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/v1/article")
public class ArticleHomeController {

    @Autowired
    ApArticleService apArticleService;

    /**
     * 首页
     * @param dto
     * @return
     */
    @PostMapping("load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto){
//        return apArticleService.load(null,dto);
        return apArticleService.load2(null, dto, true);
    }
    /**
     * 加载最新   下拉
     * @param dto
     * @return
     */
    @PostMapping("loadnew")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(ArticleConstants.LOADTYPE_LOAD_NEW, dto);
    }
    /**
     * 加载更多  上拉
     * @param dto
     * @return
     */
    @PostMapping("loadmore")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(ArticleConstants.LOADTYPE_LOAD_MORE, dto);
    }

    /**
     * 文章微服务提供  文章 保存方法   供自媒体微服务 审核文章通过后 调用
     * ap_article  ap_article_content   ap_article_config
     * @param dto
     * @return
     */
    @PostMapping("save")
    public ResponseResult save(@RequestBody ArticleDto dto){
        /*try {
            Thread.sleep(20000);//休眠20s
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        return apArticleService.saveArticle(dto);
    }


    /**
     * 详情页  回显用户行为
     * @return
     */
    @PostMapping("load_article_behavior")
    public ResponseResult loadArticleBehaviro(@RequestBody ArticleInfoDto dto){
        return  apArticleService.loadArticleBehaviro(dto);
    }

}
